// 封装ajax，直接传入大对象
function ajax(options) {
  let det = {
    url: "",
    method: "GET",
    async: true,
    data: {},
    headers: {},
    success: function () {
      console.log("成功");
    },
    error: function () {
      console.log("失败");
    },
  };

  let { url, method, async, data, headers, success, error } = {
    ...det,
    ...options,
  };

  let xhr = new XMLHttpRequest();
  let mes = "";
  xhr.open(method, url, async);

  //分类讨论,post，put，patch需要传mes
  // json数据
    if(headers["Content-Type"] == "application/json"){
      xhr.setRequestHeader("Content-Type", "application/json");
      mes = JSON.stringify(data);
    }
  xhr.send(mes);
}
